home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / text / misc / nenscript1_3.lha / postscri.c < prev    next >
C/C++ Source or Header  |  1992-11-24  |  23KB  |  745 lines

  1. /*
  2.  *   $Id: postscri.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
  3.  *
  4.  *   This code was written by Craig Southeren whilst under contract
  5.  *   to Computer Sciences of Australia, Systems Engineering Division.
  6.  *   It has been kindly released by CSA into the public domain.
  7.  *
  8.  *   Neither CSA or me guarantee that this source code is fit for anything,
  9.  *   so use it at your peril. I don't even work for CSA any more, so
  10.  *   don't bother them about it. If you have any suggestions or comments
  11.  *   (or money, cheques, free trips =8^) !!!!! ) please contact me
  12.  *   care of geoffw@extro.ucc.oz.au
  13.  *
  14.  *   Latin1 caracter set handling and fraction point sizes added by
  15.  *   Jonas Lagerblad (jonas@sisu.se).
  16.  */
  17.  
  18. #include "machdep.h"
  19. #include "defs.h"
  20.  
  21.  
  22. #include "paper.h"
  23. #include "postscri.h"
  24. #include "fontwidt.h"
  25. #include "font_lis.h"
  26.  
  27. #include <ctype.h>
  28.  
  29. /********************************
  30.   defines
  31.  ********************************/
  32.  
  33. #define    TAB     0x9
  34.  
  35. /********************************
  36.   imports
  37.  ********************************/
  38.  
  39. #include "main.h"
  40.  
  41. /********************************
  42.   exports
  43.  ********************************/
  44.  
  45.  
  46. /********************************
  47.   globals
  48.  ********************************/
  49.  
  50. static int  touched_page = False;
  51. static char *CurrentFilename;
  52. static int  WrapFlag;
  53. static int  GaudyFlag;
  54. static int  TabStop;
  55.  
  56. static long Columns;            /* number of columns */
  57. static long X;
  58. static long Y;
  59. static long BFH;                /* body font height */
  60. static long BFW;                /* body font width */
  61. static long TFH;                /* title font height */
  62. static long PageNum;            /* page number within each documenr printed */
  63. static long PageCount;            /* total number of pages printed */
  64. static int  TitleEnabled;        /* True if title to be displayed */
  65.  
  66. static long PW;                /* page width transformed for landscape mode */
  67. static long PH;                /* page height transformed for landscape mode */
  68. static long LM;                /* left margin */
  69. static long RM;                /* right margin */
  70. static long TM;                /* top */
  71. static long BM;                /* bottom margin */
  72. static long WW;                /* width of current print window */
  73. static unsigned int CPL;    /* characters per line */
  74. static long CC;                /* current column */
  75. static long LineNumber;            /* number of line on page (1 top n) */
  76. static long LinesPerPage;        /* number of lines per page, or 0 if to use default */
  77. static char *Classification;        /* points to string to use for classification */
  78. static long ColumnSep;      /* width between columns */
  79.  
  80. static long ClassY;            /* Y location to print classification at */
  81. static long TitleY;            /* Y location to print title at */
  82. static long StartY;            /* Y location to print text from */
  83. static long EndY;            /* Y location to print text down to */
  84. static long ClassBottomY;        /* Y location to print bottom classification at */
  85.  
  86.  
  87.  
  88. /*
  89.  * forward declarations if in ANSI mode
  90.  */
  91.  
  92. #ifdef __STDC__
  93. void          PrintPSString   (FILE *, unsigned char *, long);
  94. void          EndPage         (FILE *);
  95. void          StartPage       (FILE *);
  96. void          PrintLine       (FILE *, char *, long, int);
  97. static char * ExtractFontSize (char *, long *);
  98.  
  99. char *font;
  100.  
  101. #endif
  102.  
  103.  
  104. /********************************
  105.   PrintPSString
  106.     Print a string of ASCII characters of length "len" as a
  107.     PostScript string, i.e. enclosed in brackets and with appropriate
  108.     escape characters.
  109.  ********************************/
  110.  
  111. void PrintPSString (stream, line, len)
  112.  
  113. FILE *stream;
  114. unsigned char *line;
  115. long len;
  116.  
  117. {
  118.   register long i;
  119.   register unsigned char * str = line;
  120.  
  121.   fprintf (stream, "(");
  122.   for (i = 0; i < len ; i++)
  123.       if ( str[i] & 0x80 )
  124.       fprintf (stream, "\\%03o", str[i]);
  125.       else
  126.       fprintf (stream, "%s%c", str[i] == ')'  ||
  127.                              str[i] == '('  ||
  128.                  str[i] == '\\' ? "\\" : "", str[i]);
  129.   fprintf (stream, ")");
  130. }
  131.  
  132. /********************************
  133.   ExtractFontSize
  134.     Extracts the fontsize from a font type description like "Courier10".
  135.     Also, copy the font name to the fontname ptr
  136.  ********************************/
  137.  
  138. static char * ExtractFontSize (font, fontsize)
  139.  
  140. char *font;
  141. long *fontsize;
  142.  
  143. {
  144.   char *p, *s, *t;
  145.   int i;
  146.   extern double atof();
  147.  
  148.   /* get ptr to end of string */
  149.   p = &font[strlen(font)-1];
  150.  
  151.   /* move backwards until we find a character that is not a digit */
  152.   while (p > font && (isdigit (*p) || *p == '.'))
  153.     p--;
  154.  
  155.   /* extract the font size */
  156.   *fontsize = atof (++p) * SCALE;
  157.  
  158.   /* now duplicate and copy the font name */
  159.   t = s = (char *)malloc (p - font + 1);
  160.   for (i = p - font; i> 0;i--)
  161.     *t++ = *font++;
  162.   *t = '\0';
  163.  
  164.   return s;
  165. }
  166.  
  167.  
  168.  
  169.  
  170. /********************************
  171.   StartPage
  172.     Called to start a new page
  173.  ********************************/
  174.  
  175. void StartPage (stream)
  176.  
  177. FILE *stream;
  178.  
  179. {
  180.   /* insert a page marker as per the Structuring conventions */
  181.   fprintf (stream, "%%%%Page: %li %li\n", PageNum, PageCount);
  182.  
  183.   /* call the StartPage procedure with the appropriate arguments */
  184.   fprintf (stream, "(%li) ", PageNum);
  185.   PrintPSString (stream, CurrentFilename, strlen (CurrentFilename));
  186.   fprintf (stream, " StartPage\n");
  187.  
  188.   /* set X and Y location */
  189.   X = LM;
  190.   Y = StartY;
  191.  
  192.   /* set the column back to column 0 */
  193.   CC = 0;
  194.  
  195.   /* set the line number to line # 1 */
  196.   LineNumber = 1;
  197.  
  198.   /* we have now touched the page */
  199.   touched_page = True;
  200. }
  201.  
  202.  
  203. /********************************
  204.   EndPage
  205.     Called to complete a page
  206.  ********************************/
  207.  
  208. void EndPage (stream)
  209.  
  210. FILE *stream;
  211.  
  212. {
  213.   /* call the end page procedure */
  214.   fprintf (stream, "EndPage\n");
  215.  
  216.   /* increment both the job and document page counters */
  217.   PageNum++;
  218.   PageCount++;
  219.  
  220.   /* now we haven't touched the page */
  221.   touched_page = False;
  222. }
  223.  
  224.  
  225. /*******************************
  226.  
  227.   EndColumn
  228.  
  229.  *******************************/
  230.  
  231. void EndColumn (stream)
  232.  
  233. FILE *stream;
  234.  
  235. {
  236.   LineNumber = 1;
  237.   CC++;
  238.   if (CC == Columns)
  239.     EndPage (stream);
  240.   else {
  241.     X += (ColumnSep * SCALE) + WW;
  242.     Y = StartY;
  243.   }
  244. }
  245.  
  246.  
  247. /********************************
  248.   PrintLine
  249.     Called to print a line which has been chopped to
  250.     the correct length already. The "first" flag indicates
  251.     whether the line is a normal line or a continuation line.
  252.     This routine performs the skipping for indents.
  253.  ********************************/
  254.  
  255. void PrintLine (stream, line, count, first)
  256.  
  257. FILE *stream;
  258. char *line;
  259. long  count;
  260. int  first;
  261.  
  262. {
  263.   long i;
  264.  
  265.   if (!touched_page)
  266.     StartPage (stream);
  267.  
  268.   /* make i point to the first non-blank character on the line */
  269.   for (i = 0; i < count && line[i] == ' ';i++)
  270.     ;
  271.  
  272.   if (i < count) {
  273.     if (!first)
  274.       fprintf (stream, "%li %li K ", Y, X);
  275.     PrintPSString (stream, &line[i], count - i);
  276.     if (i > 0)
  277.       fprintf (stream, " %li %li %i L\n", Y, X, i);
  278.     else
  279.       fprintf (stream, " %li %li T\n", Y, X);
  280.   }
  281.  
  282.   Y -= BFH * 11 / 10;        /* put a little bit of extra spacing between the characters */
  283.   LineNumber++;
  284.  
  285.   if (Y < EndY || (LinesPerPage > 0 && LineNumber > LinesPerPage))
  286.     EndColumn (stream);
  287. }
  288.  
  289. /********************************
  290.   WriteLine
  291.     Writes a line to the output. This routine performs the wrapping and tab expansion
  292.  ********************************/
  293.  
  294. void WriteLine (stream, line)
  295.  
  296. FILE *stream;
  297. char *line;
  298.  
  299. {
  300.   int first = True;
  301.   char *p;
  302.   char *q;
  303.   int col;
  304.   int i;
  305.  
  306.   char full_line[8192];
  307.  
  308.   /* expand tabs if we have to */
  309.   if (strchr (line, TAB) != NULL) {
  310.     col = 0;
  311.     q = full_line;
  312.     for (p = line; *p ; p++)
  313.       if (*p != TAB) {
  314.         *q++ = *p;
  315.         col = (col + 1) % TabStop;
  316.       } else {
  317.         for (i = TabStop - col; i > 0; i--)
  318.           *q++ = ' ';
  319.         col = 0;
  320.       }
  321.     *q = 0;
  322.     line = full_line;
  323.   }
  324.  
  325.   if (WrapFlag) {
  326.     while (strlen(line) > CPL) {
  327.       PrintLine (stream, line, CPL, first);
  328.       first = False;
  329.       line += CPL;
  330.     }
  331.     PrintLine (stream, line, strlen(line), first);
  332.   } else
  333.     PrintLine (stream, line, MIN(strlen(line), CPL), True);
  334. }
  335.  
  336.  
  337. /********************************
  338.   StartDocument
  339.     Called when a new document is to be printed. Not to be confused with
  340.     starting the job.
  341.  ********************************/
  342.  
  343. void StartDocument (stream, filename)
  344.  
  345. FILE *stream;
  346. char *filename;
  347.  
  348. {
  349.   /* restart the internal page number */
  350.   PageNum = 1;
  351.  
  352.   /* indicate that the first page has not yet been touched */
  353.   touched_page = False;
  354.  
  355.   /* and set the current filename */
  356.   CurrentFilename = filename;
  357. }
  358.  
  359.  
  360. /********************************
  361.   EndDocument
  362.     Called when a document has been completed.
  363.  ********************************/
  364.  
  365. void EndDocument (stream)
  366.  
  367. FILE *stream;
  368.  
  369. {
  370.   /* if we have drawn a partial page, finish it off properly */
  371.   if (touched_page)
  372.     EndPage (stream);
  373. }
  374.  
  375.     static char pspro_latin1_data[] = { "\
  376. /newcodes    % foreign character encodings\n\
  377. [\n\
  378. 160/space 161/exclamdown 162/cent 163/sterling 164/currency\n\
  379. 165/yen 166/brokenbar 167/section  168/dieresis 169/copyright\n\
  380. 170/ordfeminine 171/guillemotleft 172/logicalnot 173/hyphen 174/registered\n\
  381. 175/macron 176/degree 177/plusminus 178/twosuperior 179/threesuperior\n\
  382. 180/acute 181/mu 182/paragraph  183/periodcentered 184/cedilla\n\
  383. 185/onesuperior 186/ordmasculine 187/guillemotright 188/onequarter\n\
  384. 189/onehalf 190/threequarters 191/questiondown 192/Agrave 193/Aacute\n\
  385. 194/Acircumflex 195/Atilde 196/Adieresis 197/Aring 198/AE 199/Ccedilla\n\
  386. 200/Egrave 201/Eacute 202/Ecircumflex 203/Edieresis 204/Igrave  205/Iacute\n\
  387. 206/Icircumflex 207/Idieresis 208/Eth 209/Ntilde 210/Ograve 211/Oacute\n\
  388. 212/Ocircumflex 213/Otilde  214/Odieresis 215/multiply 216/Oslash\n\
  389. 217/Ugrave 218/Uacute 219/Ucircumflex 220/Udieresis 221/Yacute 222/Thorn\n\
  390. 223/germandbls 224/agrave 225/aacute 226/acircumflex 227/atilde\n\
  391. 228/adieresis 229/aring 230/ae 231/ccedilla  232/egrave 233/eacute\n\
  392. 234/ecircumflex 235/edieresis 236/igrave 237/iacute 238/icircumflex\n\
  393. 239/idieresis 240/eth 241/ntilde 242/ograve 243/oacute 244/ocircumflex\n\
  394. 245/otilde 246/odieresis 247/divide 248/oslash 249/ugrave  250/uacute\n\
  395. 251/ucircumflex 252/udieresis 253/yacute 254/thorn 255/ydieresis\n\
  396. ] def\n\
  397. \n\
  398. /reencdict 12 dict def\n\
  399. \n\
  400. " };
  401.  
  402.     static char pspro_latin1_func[] = { "\n\
  403.     % change fonts using ISO Latin1 characters\n\
  404. /ChgFnt        % size psname natname  =>  font\n\
  405. {\n\
  406.     dup FontDirectory exch known    % is re-encoded name known?\n\
  407.     { exch pop }            % yes, get rid of long name\n\
  408.     { dup 3 1 roll ReEncode } ifelse    % no, re-encode it\n\
  409.     findfont exch scalefont setfont\n\
  410. } def\n\
  411. \n\
  412. /ReEncode    %\n\
  413. {\n\
  414.     reencdict begin\n\
  415.     /newname exch def\n\
  416.     /basename exch def\n\
  417.     /basedict basename findfont def\n\
  418.     /newfont basedict maxlength dict def\n\
  419.     basedict\n\
  420.     { exch dup /FID ne\n\
  421.         { dup /Encoding eq\n\
  422.         { exch dup length array copy newfont 3 1 roll put }\n\
  423.         { exch newfont 3 1 roll put } ifelse\n\
  424.         }\n\
  425.         { pop pop } ifelse\n\
  426.     } forall\n\
  427.     newfont /FontName newname put\n\
  428.     newcodes aload pop newcodes length 2 idiv\n\
  429.     { newfont /Encoding get 3 1 roll put } repeat\n\
  430.     newname newfont definefont pop\n\
  431.     end\n\
  432. } def\n\
  433. \n\
  434. " };
  435.  
  436. /********************************
  437.   StartJob
  438.     Called when a new job is to be started. This performs all of the
  439.     PostScript initialisation
  440.  ********************************/
  441.  
  442. void StartJob (stream, filename, landscape, columns, BodyFont,
  443.                TitleFont, wrap, enabletitle, title, copies, gaudy, force_lines, classification, papermetrics, tabstop)
  444.  
  445.  
  446. FILE * stream;
  447. int  landscape;
  448. int  columns;
  449. char *BodyFont;
  450. char *TitleFont;
  451. int  wrap;
  452. int  enabletitle;
  453. char *title;
  454. int  copies;
  455. int  gaudy;
  456. int  force_lines;
  457. char *filename;
  458. char *classification;
  459. struct PaperMetrics *papermetrics;
  460. int  tabstop;
  461.  
  462. {
  463.   char *bodyfont;
  464.   char *titlefont;
  465.   char *gaudyPNfont;
  466.   char *gaudytitlefont;
  467.   char *gaudydatefont;
  468.   char *classfont;
  469.   long  gaudyPNfontsize;
  470.   long  gaudytitlefontsize;
  471.   long  gaudydatefontsize;
  472.   long  classfontsize;
  473.  
  474.   time_t thetime = time(NULL);
  475.   char  * timestring = strtok(ctime (&thetime), "\n");  /* a simple time string */
  476.   struct tm *tm      = localtime (&thetime);
  477.   char tm_string[15];
  478.   char dt_string[15];
  479.  
  480.   /* get the time and date strings */
  481.   GETDATE (tm, dt_string);
  482.   GETTIME (tm, tm_string);
  483.  
  484.   /* make local copies of various flags */
  485.   WrapFlag       = wrap;
  486.   GaudyFlag      = gaudy && enabletitle;
  487.   TitleEnabled   = enabletitle;
  488.   Columns        = columns;
  489.   LinesPerPage   = force_lines;
  490.   Classification = classification;
  491.   ColumnSep      = papermetrics->ColumnSep;
  492.   TabStop        = tabstop;
  493.  
  494.   /* get the size and width of the font used for the body of the text */
  495.   bodyfont = ExtractFontSize (BodyFont, &BFH);
  496.   BFW      = GetFontWidth    (bodyfont, BFH);
  497.  
  498.   /* extract various font sizes */
  499.   gaudyPNfont    = ExtractFontSize (papermetrics->GaudyPNFont,    &gaudyPNfontsize);
  500.   gaudytitlefont = ExtractFontSize (papermetrics->GaudyTitleFont, &gaudytitlefontsize);
  501.   gaudydatefont  = ExtractFontSize (papermetrics->GaudyDateFont,  &gaudydatefontsize);
  502.  
  503.   /* get the size of the font used for the title */
  504.   titlefont = ExtractFontSize (TitleFont, &TFH);
  505.  
  506.   /* now the classification font, if there is one */
  507.   if (Classification != NULL)
  508.     classfont = ExtractFontSize (papermetrics->ClassificationFont, &classfontsize);
  509.  
  510.   /* output obligatory Postscript header */
  511.   fprintf (stream, "%%!PS-Adobe-1.0\n");
  512.  
  513.   /* output the filename of the first file as the title */
  514.   fprintf (stream, "%%%%Title: %s\n", filename);
  515.  
  516.   /* put version of program in as creator */
  517.   fprintf (stream, "%%%%Creator: %s\n", version_string);
  518.  
  519.   /* extract the users full name and put in as the creator */
  520.   fprintf (stream, "%%%%For: %s\n", USERNAME);
  521.  
  522.   /* put in the time as a string */
  523.   fprintf (stream, "%%%%CreationDate: %s\n", timestring);
  524.  
  525.   /* output the font list */
  526.   add_font_to_list (titlefont);
  527.   add_font_to_list (bodyfont);
  528.   if (GaudyFlag) {
  529.     add_font_to_list (gaudyPNfont);
  530.     add_font_to_list (gaudydatefont);
  531.     add_font_to_list (gaudytitlefont);
  532.   }
  533.   if (Classification != NULL)
  534.     add_font_to_list (classfont);
  535.  
  536.   fprintf (stream, "%%%%DocumentFonts: ");
  537.   enumerate_fonts (stream);
  538.   fprintf (stream, "\n");
  539.  
  540.   /* initialise the document page counter and indicate that the page count info
  541.      can be found at the end of the document. This copout means we don't have
  542.      to store the output data in a temporary file (like enscript) just so we can
  543.      find out how many pages there are */
  544.   PageCount = 1;
  545.   fprintf (stream, "%%%%Pages: (atend)\n");
  546.  
  547.   /* End of header marker */
  548.   fprintf (stream, "%%%%EndComments\n");
  549.  
  550.   /* allow Latin-1 character set by remapping most characters above 127 */
  551.   fprintf (stream, "%s\n%s", pspro_latin1_data, pspro_latin1_func); 
  552.  
  553.   /* scale the coordinate system by SCALE so we can use integer arithmetic
  554.      without losing accuracy */
  555.   fprintf (stream, "1 %li div dup scale\n", SCALE);
  556.  
  557.   /* use the Postscript mechanism for duplicating pages, rather than using a flag to lpr.
  558.      This mechanism means less data (I think!!) but it requires you to edit the file
  559.      if you want to print a different number of copies later. It is so rarely used that
  560.      it isn't really an issue anyway!! */
  561.   fprintf (stream, "/#copies %i def\n", copies);
  562.  
  563.   /* rotate the page if using landscape mode, and set PW and PH to the page width and height
  564.      as determined by the SCALE factor */
  565.   if (landscape) {
  566.     PW = papermetrics->PaperHeight * SCALE;
  567.     PH = papermetrics->PaperWidth * SCALE;
  568.  
  569.     LM = PAGE_BOT_MARGIN * SCALE;
  570.     RM = PAGE_TOP_MARGIN * SCALE;
  571.  
  572.     TM = PAGE_LEFT_MARGIN * SCALE;
  573.     BM = PAGE_RIGHT_MARGIN * SCALE;
  574.  
  575.     fprintf (stream, "90 rotate %li %li translate\n",PAGE_LANDSCAPE_XOFFS, PAGE_LANDSCAPE_YOFFS - PH);
  576.   } else {
  577.     PH = papermetrics->PaperHeight * SCALE;
  578.     PW = papermetrics->PaperWidth * SCALE;
  579.  
  580.     LM = PAGE_LEFT_MARGIN * SCALE;
  581.     RM = PAGE_RIGHT_MARGIN * SCALE;
  582.  
  583.     TM = PAGE_TOP_MARGIN * SCALE;
  584.     BM = PAGE_BOT_MARGIN * SCALE;
  585.   }
  586.  
  587.    /* calculate the width of the "window" in which we draw text, and from that calculate the
  588.      number of characters per line (CPL) */
  589.   WW = (PW - (LM + RM) - ((columns - 1) * papermetrics->ColumnSep * SCALE)) / columns;
  590.   CPL = (unsigned int)(WW / BFW);
  591.  
  592.   /* calculate the top position at which we start drawing text */
  593.   StartY = PH - TM;
  594.  
  595.   /* adjust starting position if we are printing security classification */
  596.   if (Classification != NULL) {
  597.     StartY -= classfontsize;
  598.     ClassY = StartY;
  599.   }
  600.  
  601.   /* adjust starting position if we are printing title */
  602.   if (TitleEnabled) {
  603.     if (GaudyFlag)  {
  604.       TitleY = StartY;
  605.       StartY -= (papermetrics->GaudyBoxHeight * SCALE) + BFH; /* StartY -= BH + BFH; */
  606.     } else {
  607.       StartY -= TFH;
  608.       TitleY = StartY;
  609.       StartY -= BFH;
  610.     }
  611.   }
  612.  
  613.   /* move down one line below for start of text */
  614.   StartY -= BFH;
  615.  
  616.   /* calculate the last location on the page to be printing text */
  617.   EndY = BM;
  618.   if (Classification != NULL) {
  619.     ClassBottomY = BM;
  620.     EndY += classfontsize;
  621.   }
  622.  
  623.   /* define a variable for our body font, and calculate the character width for later use */
  624.   fprintf (stream, "/BodyF { %li /%s /%s-Latin1 ChgFnt } def\n", BFH, bodyfont,
  625.      bodyfont);
  626.   fprintf (stream, "/CW BodyF ( ) stringwidth pop def\n");
  627.  
  628.   /* define variables for various other font used - title, gaudy page number, gaudy date, gaudy title */
  629.   fprintf (stream, "/Titlef {  %li /%s /%s-Latin1 ChgFnt } def\n", TFH, titlefont,
  630.      titlefont);
  631.   if (GaudyFlag) {
  632.     fprintf (stream, "/Gpnf {  %li /%s /%s-Latin1 ChgFnt } def\n", gaudyPNfontsize,
  633.      gaudyPNfont, gaudyPNfont);
  634.     fprintf (stream, "/Gdatef { %li /%s /%s-Latin1 ChgFnt } def\n",
  635.      gaudydatefontsize, gaudydatefont, gaudydatefont);
  636.     fprintf (stream, "/Gtitlef { %li /%s /%s-Latin1 ChgFnt } def\n",
  637.      gaudytitlefontsize, gaudytitlefont, gaudytitlefont);
  638.   }
  639.  
  640.   /* define procedures for drawing continuation line markers, continuation lines, normal lines, and performing indents */
  641.   fprintf (stream, "/K         { -2 CW mul add exch moveto (+) show } def\n");
  642.   fprintf (stream, "/L         { CW mul add exch moveto show } def\n");
  643.   fprintf (stream, "/T         { exch moveto show } def\n");
  644.   fprintf (stream, "/M         { CW mul 0 rmoveto } def\n");
  645.   fprintf (stream, "/Centre    { dup stringwidth pop 2 div neg 0 rmoveto } def\n");
  646.  
  647.   /* define procedures for drawing gaudy page numbers, gaudy boxes, gaudy bars and gaudy titles */
  648.   if (GaudyFlag) {
  649.     fprintf (stream, "/Gb        { newpath moveto %li 0 rlineto 0 %li rlineto -%li 0 rlineto fill } def\n",
  650.                                       papermetrics->GaudyBoxWidth  * SCALE,   /* BW */
  651.                                       papermetrics->GaudyBoxHeight * SCALE,   /* BH */
  652.                                       papermetrics->GaudyBoxWidth  * SCALE);  /* BW */
  653.     fprintf (stream, "/Gr        { newpath moveto %li 0 rlineto 0 %li rlineto -%li 0 rlineto fill } def\n",
  654.                                        PW - (LM + RM) - (2 * papermetrics->GaudyBoxWidth  * SCALE), papermetrics->GaudyBarHeight  * SCALE,
  655.                                        PW - (LM + RM) - (2 * papermetrics->GaudyBoxWidth  * SCALE));
  656.     fprintf (stream, "/G         { %s setgray %li %li Gb %li %li Gb %s setgray %li %li Gr } def\n",
  657.                     BOXGRAY,
  658.                     LM, TitleY - (papermetrics->GaudyBoxHeight * SCALE),                          /* pos of left box */
  659.                       PW - RM - (papermetrics->GaudyBoxWidth * SCALE), TitleY - (papermetrics->GaudyBoxHeight * SCALE),                /* pos of right box */
  660.                     BARGRAY,
  661.                     LM + (papermetrics->GaudyBoxWidth * SCALE), TitleY - (papermetrics->GaudyBoxHeight * SCALE));               /* pos of bar */
  662.   }
  663.  
  664.   /* define stuff for security strings */
  665.   if (Classification != NULL) {
  666.     fprintf (stream, "/Classf {  %li /%s /%s-Latin1 ChgFnt } def\n", classfontsize,
  667.      classfont, classfont);
  668.     fprintf (stream, "/ClassString ");
  669.     PrintPSString (stream, Classification, strlen(classification));
  670.     fprintf (stream, " def\n");
  671.   }
  672.  
  673.   /* if we have titles enabled, define an appropriate procedure for drawing it */
  674.   /* define the start page procedure used to start every page */
  675.   fprintf (stream, "/StartPage { /SavedPage save def\n");
  676.   if (Classification != NULL)
  677.       fprintf (stream, "  Classf %li %li moveto ClassString Centre 0 setgray show\n", PW / 2, ClassY);
  678.  
  679.   if (TitleEnabled) {
  680.     if (GaudyFlag) {
  681.       fprintf (stream, "  G\n");                                                   /* draw boxes */
  682.       fprintf (stream, "  Gtitlef %li %li moveto Centre 0 setgray show\n",   /* title */
  683.                                          ((LM + (papermetrics->GaudyBoxWidth  * SCALE)) +
  684.                                            (PW - RM - (papermetrics->GaudyBoxWidth  * SCALE))) / 2L,
  685.                                          TitleY - (papermetrics->GaudyBoxHeight * SCALE) +
  686.                                          (((papermetrics->GaudyBarHeight  * SCALE) * 7L / 10L) / 2L));
  687.       if (title != NULL) {
  688.         fprintf (stream, "%li %li moveto ",
  689.                                          ((LM + (papermetrics->GaudyBoxWidth * SCALE)) + (PW - RM - (papermetrics->GaudyBoxWidth * SCALE))) / 2L,
  690.                                          TitleY - (((papermetrics->GaudyBarHeight * SCALE) * 7L / 10L) / 2L));
  691.         PrintPSString (stream, title, strlen(title));
  692.         fprintf (stream, " Centre show\n");
  693.       }
  694.       fprintf (stream, "  Gpnf    %li %li moveto Centre 1 setgray show\n",   /* page number */
  695.                                          PW - RM - ((papermetrics->GaudyBoxWidth * SCALE) / 2L),
  696.                                          TitleY - ((papermetrics->GaudyBoxHeight * SCALE) / 2L) - gaudyPNfontsize * 7L / 20L);
  697.       fprintf (stream, "  Gdatef  %li %li moveto (%s) Centre 0 setgray show\n",
  698.                      LM + ((papermetrics->GaudyBoxWidth * SCALE) / 2L),
  699.                      TitleY - ((papermetrics->GaudyBoxHeight * SCALE) * 3L / 5L) - gaudydatefontsize * 7L / 10L, tm_string);
  700.       fprintf (stream, "                  %li %li moveto (%s) Centre show\n",
  701.                      LM + ((papermetrics->GaudyBoxWidth * SCALE) / 2L),
  702.                      TitleY - ((papermetrics->GaudyBoxHeight * SCALE) * 3L / 5L) + gaudydatefontsize * 7L / 10L, dt_string);
  703.     } else {
  704.       fprintf (stream, "  0 setgray Titlef %li %li moveto ", LM, TitleY);
  705.       if (title != NULL) {
  706.         fprintf (stream, "pop pop ");
  707.         PrintPSString (stream, title, strlen(title));
  708.         fprintf (stream, " show\n");
  709.       } else {
  710.         fprintf (stream, "show 8 M ");
  711.         PrintPSString (stream, timestring, strlen (timestring));
  712.         fprintf (stream, " show 8 M show\n");
  713.       }
  714.     }
  715.   }
  716.   fprintf (stream, "  BodyF 0 setgray } def\n");
  717.  
  718.   /* define end page procedure */
  719.   fprintf (stream, "/EndPage   {");
  720.   if (GaudyFlag && Columns == 2)
  721.     fprintf (stream, " %li %li moveto %li -%li rlineto stroke ", LM + WW + (papermetrics->ColumnSep * SCALE / 2), StartY, 0L, StartY - EndY);
  722.   if (Classification != NULL)
  723.       fprintf (stream, "  Classf %li %li moveto ClassString Centre 0 setgray show\n", PW / 2, ClassBottomY);
  724.   fprintf (stream, "showpage SavedPage restore } def\n");
  725.  
  726.   /* end of the header */
  727.   fprintf (stream, "%%%%EndProlog\n");
  728. }
  729.  
  730. /********************************
  731.    EndJob
  732.  ********************************/
  733.  
  734. void EndJob (stream)
  735.  
  736. FILE *stream;
  737.  
  738. {
  739.   /* indicate this is the end of the file */
  740.   fprintf (stream, "%%%%Trailer\n");
  741.  
  742.   /* now we know how many pages there are!! */
  743.   fprintf (stream, "%%%%Pages: %li\n", PageCount - 1);
  744. }
  745.